package cn.edu.klmy.controller;

import cn.edu.klmy.dao.IParamDao;
import cn.edu.klmy.models.param.SystemParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author 顾伟
 *         创建日期：13-4-14
 */
@Controller
@RequestMapping("/param")
public class ParamController {
    @Autowired
    private IParamDao paramDao;

    @RequestMapping("/list")
    @ResponseBody
    public SystemParam loadSystemParam(HttpServletRequest request){
        HttpSession session = request.getSession();
        return (SystemParam)session.getAttribute("param");
    }

    @RequestMapping("/update")
    @ResponseBody
    public boolean updateSystemParam(HttpServletRequest request,@ModelAttribute SystemParam systemParam){
        boolean updated=  paramDao.updateCurrentParam(systemParam);
        if(updated) {
            HttpSession session = request.getSession();
            session.setAttribute("param",systemParam);
        }
        return paramDao.updateCurrentParam(systemParam);
    }
}
